// 统一管理权限相关接口
// 统一管理权限相关接口
import http from '@/utils/request'

import type { allRoleResponse, roleData, allPermissionResponse } from './type.ts'

// 通过枚举统一管理接口
enum API {
  ALLROLE_URL = '/admin/acl/role/',
  ADDROLE_URL = '/admin/acl/role/save',
  EDITROLE_URL = '/admin/acl/role/update',
  ALLPREMISSION_URL = '/admin/acl/permission/toAssign/',
  SETPREMISSION_URL = '/admin/acl/permission/doAssign/?',
  REMOVEROLE_URL = '/admin/acl/role/remove/',
}

// 删除角色
export const removeRoleAPI = (id: number) => http.delete<any, any>(API.REMOVEROLE_URL + id)

// 分配权限
export const setPermissionAPI = (roleId: number, permissionId: number[]) => http.post<any, any>(API.SETPREMISSION_URL, `roleId=${roleId}&permissionId=${permissionId}`)

// 获取权限菜单与按钮数据
export const getPermissionListAPI = (id: string) => http.get<any, allPermissionResponse>(API.ALLPREMISSION_URL + id)

// 修改角色
export const editRoleAPI = (data: roleData) => http.put<any, any>(API.EDITROLE_URL, data)

// 新增角色
export const addRoleAPI = (data: roleData) => http.post<any, any>(API.ADDROLE_URL, data)

// 获取角色列表
export const allRoleListAPI = (page: number | string, limit: number | string, roleName: string) => http.get<any, allRoleResponse>(API.ALLROLE_URL + `${page}/${limit}?roleName=${roleName}`)